package com.ljb.demo.v;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by ljb on 2017/6/7.
 */

public abstract class BaseFragment extends Fragment {

    protected Context c;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        c = getContext();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(getLayoutId(), container, false);
        initUI(rootView, savedInstanceState);
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        iniData();
    }

    /**
     * 获取根布局Id
     *
     * @return
     */
    protected abstract int getLayoutId();

    /**
     * 初始化UI
     *
     * @param rootView
     * @param savedInstanceState
     */
    protected abstract void initUI(View rootView, Bundle savedInstanceState);

    /**
     * 初始化数据
     */
    protected abstract void iniData();
}
